﻿using AutoMapper;
using B.S.Database.Domain.Entity;
using B.S.Database.ErrorCode;
using B.S.Database.Interface.Interface;
using B.S.Database.Write.Api.Application.Commands.Breeding;
using MediatR;

namespace B.S.Database.Write.Api.Application.CommandHandler.Breeding
{
    public class ImmuneUpdateCommandHandler : IRequestHandler<ImmuneUpdateCommands, Apiresult<object>>
    {
        private readonly IBaseResotity<Immune_Infomation> immuneRepo;
        private readonly IMapper mapper;

        public ImmuneUpdateCommandHandler(IBaseResotity<Immune_Infomation> ImmuneRepo,IMapper mapper)
        {
            immuneRepo = ImmuneRepo;
            this.mapper = mapper;
        }
        public Task<Apiresult<object>> Handle(ImmuneUpdateCommands request, CancellationToken cancellationToken)
        {
            Apiresult<object> res = new Apiresult<object>();
            var list = immuneRepo.GetAll().FirstOrDefault(c=>c.ImmuneId == request.ImmuneId); 
            if (list == null)
            {
                res.Code = ApiEnums.错误;
                res.Message = ApiEnums.错误.ToString();
                return Task.FromResult(res);
            }
            else
            {
                res.Code = ApiEnums.成功;
                res.Message = ApiEnums.成功.ToString();
                list.IsDelete = true;
                immuneRepo.Update(list);
            }
            return Task.FromResult(res);
        }
    }
}
